home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / nullfile / RCS / nullfile.c,v < prev   
Encoding:
Text File  |  1991-04-15  |  2.3 KB  |  133 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    jhh:1.1; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     91.04.14.22.08.17;  author jhh;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * nullfile.c --
  27.  *
  28.  *    Description.
  29.  *
  30.  * Copyright 1989 Regents of the University of California
  31.  * Permission to use, copy, modify, and distribute this
  32.  * software and its documentation for any purpose and without
  33.  * fee is hereby granted, provided that the above copyright
  34.  * notice appear in all copies.  The University of California
  35.  * makes no representations about the suitability of this
  36.  * software for any purpose.  It is provided "as is" without
  37.  * express or implied warranty.
  38.  */
  39.  
  40. #ifndef lint
  41. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.2 89/01/07 04:12:18 rab Exp $ SPRITE (Berkeley)";
  42. #endif /* not lint */
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46.  
  47. #define min(a,b) (((a) < (b)) ? (a) : (b) )
  48. #define BUFFER_SIZE 4096
  49.  
  50. static char     *progName;
  51.  
  52. void        Usage();
  53.  
  54.  
  55. /*
  56.  *----------------------------------------------------------------------
  57.  *
  58.  *  main--
  59.  *
  60.  *    <description>
  61.  *
  62.  * Results:
  63.  *    None.
  64.  *
  65.  * Side effects:
  66.  *    None.
  67.  *
  68.  *----------------------------------------------------------------------
  69.  */
  70.  
  71. void
  72. main(argc, argv)
  73.     int     argc;
  74.     char    *argv[];
  75. {
  76.     char     *name;
  77.     int        count;
  78.     FILE    *fp;
  79.     static char buffer[BUFFER_SIZE];
  80.     int        bytesWritten;
  81.     int        bytesToWrite;
  82.  
  83.     progName = argv[0];
  84.     if (argc != 3) {
  85.     Usage();
  86.     }
  87.     name = argv[1];
  88.     if (sscanf(argv[2], " %d", &count) != 1) {
  89.     Usage();
  90.     }
  91.     if (count < 0) {
  92.     fprintf(stderr,"Count argument must be positive.\n");
  93.     Usage();
  94.     }
  95.     fp = fopen(name,"w+");
  96.     if (fp == NULL) {
  97.     fprintf(stderr,"Unable to open file %s.\n", name);
  98.     exit(1);
  99.     }
  100.     bzero(buffer, BUFFER_SIZE);
  101.     for (bytesWritten = 0; bytesWritten < count;) {
  102.     bytesToWrite = min(BUFFER_SIZE, count - bytesWritten);
  103.     fwrite(buffer, sizeof(char), bytesToWrite, fp);
  104.     bytesWritten += bytesToWrite;
  105.    }
  106.    fclose(fp);
  107. }
  108.  
  109.  
  110. /*
  111.  *----------------------------------------------------------------------
  112.  *
  113.  * Usage --
  114.  *
  115.  *    description.
  116.  *
  117.  * Results:
  118.  *    None.
  119.  *
  120.  * Side effects:
  121.  *    None.
  122.  *
  123.  *----------------------------------------------------------------------
  124.  */
  125.  
  126. void
  127. Usage()
  128. {
  129.     (void) fprintf(stderr,"Usage: %s file count\n",progName);
  130.     exit(1);
  131. }
  132. @
  133.